#define DO_ICI					\
	if(WaitInterrupt)			\
		WaitInterrupt = 0;	\
	else							\
		{							\
		PushS16(PC);			\
		PushS16(X);				\
		PushS(A);				\
		PushS(B);				\
		PushS(CC);				\
		}							\
	CC |= F_IRQ;				\
	PC = ReadWord(0xFFF6);	\
	Interrupts2 &= ~F_TCSR_ICI;\
	AddCycles(12);

#define DO_OCI					\
	if(WaitInterrupt)			\
		WaitInterrupt = 0;	\
	else							\
		{							\
		PushS16(PC);			\
		PushS16(X);				\
		PushS(A);				\
		PushS(B);				\
		PushS(CC);				\
		}							\
	CC |= F_IRQ;				\
	PC = ReadWord(0xFFF4);	\
	Interrupts2 &= ~F_TCSR_OCI;\
	AddCycles(12);

#define DO_TOI					\
	if(WaitInterrupt)			\
		WaitInterrupt = 0;	\
	else							\
		{							\
		PushS16(PC);			\
		PushS16(X);				\
		PushS(A);				\
		PushS(B);				\
		PushS(CC);				\
		}							\
	CC |= F_IRQ;				\
	PC = ReadWord(0xFFF2);	\
	Interrupts2 &= ~F_TCSR_TOI;\
	AddCycles(12);

#define CHECK_ICI					\
	if(Interrupts2 & F_TCSR_ICI)	\
		{								\
		DO_ICI;						\
		}

#define CHECK_OCI					\
	if(Interrupts2 & F_TCSR_OCI)	\
		{								\
		DO_OCI;						\
		}

#define CHECK_TOI					\
	if(Interrupts2 & F_TCSR_TOI)	\
		{								\
		DO_TOI;						\
		}

#define DIRECT_IM				\
	tmp = Read(PC++);			\
	EA = Read(PC++);

#define INDEXED_IM			\
	tmp = Read(PC++);			\
	Indexed();

#define EXTENDED_IM			\
	tmp = Read(PC++);			\
	EA = ReadWord(PC);		\
	PC += 2;

#define ADDD					\
	tmp3 = ReadWord(EA);		\
	tmp2 = D + tmp3;			\
	CC &= ~(F_ZERO | F_NEGATIVE | F_OVERFLOW | F_CARRY);	\
	if(tmp2 & 0x10000)		\
		CC |= F_CARRY;			\
	if((tmp2 ^ D ^ tmp3 ^ (tmp2 >> 1)) & 0x8000)	\
		CC |= F_OVERFLOW;		\
	D = (u16)tmp2;				\
	CheckNZ16(D);

#define SUBD					\
	tmp3 = ReadWord(EA);		\
	tmp2 = D - tmp3;			\
	CC &= ~(F_ZERO | F_NEGATIVE | F_OVERFLOW | F_CARRY);	\
	if(tmp2 & 0x10000)		\
		CC |= F_CARRY;			\
	if((tmp2 ^ D ^ tmp3 ^ (tmp2 >> 1)) & 0x8000)	\
		CC |= F_OVERFLOW;		\
	D = (u16)tmp2;				\
	CheckNZ16(D);

#define OIM						\
	tmp |= Read(EA);			\
	CC &= ~(F_ZERO | F_NEGATIVE | F_OVERFLOW);	\
	CheckNZ(tmp);				\
	Write(EA,tmp);

#define AIM						\
	tmp &= Read(EA);			\
	CC &= ~(F_ZERO | F_NEGATIVE | F_OVERFLOW);	\
	CheckNZ(tmp);				\
	Write(EA,tmp);

#define EIM						\
	tmp ^= Read(EA);			\
	CC &= ~(F_ZERO | F_NEGATIVE | F_OVERFLOW);	\
	CheckNZ(tmp);				\
	Write(EA,tmp);

#define TIM						\
	tmp &= Read(EA);			\
	CC &= ~(F_ZERO | F_NEGATIVE | F_OVERFLOW);	\
	CheckNZ(tmp);

#define ABX						\
	X += B;

#define MUL						\
	tmp2 = A * B;				\
	D = (u16)tmp2;				\
	if(tmp2)						\
		CC &= ~F_ZERO;			\
	else							\
		CC |= F_ZERO;			\
	if(tmp2 & 0x80)			\
		CC |= F_CARRY;			\
	else							\
		CC &= ~F_CARRY;

#define PULX	X = PullS16();
#define PSHX	PushS16(X);
